# -*- coding: utf-8 -*-

import os
import datetime


def _wrap_with(code):
    def inner(text, bold=False):
        c = code
        if os.environ.get('FABRIC_DISABLE_COLORS'):
            return text
        if bold:
            c = "1;{0}".format(c)
        return "\033[{0}m{1}\033[0m".format(c, text)
    return inner


red = _wrap_with('31')
green = _wrap_with('32')
yellow = _wrap_with('33')
blue = _wrap_with('34')
magenta = _wrap_with('35')
cyan = _wrap_with('36')
white = _wrap_with('37')


uname = os.uname()
max_len = 0
for x in uname:
    if len(x) > max_len:
        max_len = len(x)


def print_title(max_len):
    print('+---------+' + '-' * (max_len+2) + '+')


def print_body(*columns):
    """
    disabled func
    """
    max_column_len = 0
    for column in columns:
        if len(column) > max_column_len:
            max_column_len = len(column)
    for column in columns:
        print('| {0} | {1:<{2}} |'.format(column,
                                          os.uname.column,
                                          max_len+max_column_len+2))


print('System report for [{0}] on {1}'.format(yellow(uname.nodename),
                                              yellow(datetime.datetime.now())))
print_title(max_len)
print('| {0} | {1:<{2}} |'.format("Sysname", green(uname.sysname), max_len+9))
print('| {0} | {1:<{2}} |'.format("Release", green(uname.release), max_len+9))
print('| {0} | {1:<{2}} |'.format("Version", green(uname.version), max_len+9))
print('| {0} | {1:<{2}} |'.format("Machine", green(uname.machine), max_len+9))
print_title(max_len)

